#include "mv_serial_data_parse.h"

void parseUartData(recv_data_t *recv_data, uint8_t *serial_data, uint16_t len)
{
    const uint8_t pack_head[2] = {0xa5, 0xa6};
    uint8_t *s = serial_data;

    for (uint16_t i = 0; i < len - 1; i++, s++)
    {
        if (*s == pack_head[0] && *(s + 1) == pack_head[1])
        {
            break;
        }
    }

    if (s == serial_data + len - 1)
    {
        recv_data->err_x = 0;

        return;
    }

    s += 2;
    recv_data->err_x = ((*s == 1) ? 1 : -1) * (*(s + 1));
}